/** for BorderLayout */
import java.awt.BorderLayout;

/** for Color */
import java.awt.Color;

/** for Dimension */
import java.awt.Dimension;

/** for Font */
import java.awt.Font;

/** for Graphics */
import java.awt.Graphics;

/** for BorderFactory*/
import javax.swing.BorderFactory;
import javax.swing.SwingConstants;

/** for JLabel*/
import javax.swing.JLabel;

/** for JPanel*/
import javax.swing.JPanel;

/**
 * HW 12b & 13b, "ControlPanel"<br><br>
 * 
 * This class is for the main control panel for the entire program. 
 * It creates all three other panels that will be used to contain
 * different parts of the window, 
 * and controls and repaints them. 
 * 
 * @author Hyun Seo Chung
 * @version 1.0 04/21/12
 */
public class ControlPanel extends JPanel {
	
	/**
	 * serialVersionUID for the ControlPanel class
	 */
	private static final long serialVersionUID = 1L;
	
	/**
	 * left panel
	 */
	private final EmptyPanel l_panel;
	
	/**
	 * middle panel
	 */
	private final PlayingPanel m_panel;
	
	/**
	 * right panel
	 */
	private final RightPanel r_panel;
	
	/**
	 * JLabel for the title
	 */
	private final JLabel title;

	/** for 10 **/
	private static final int TEN = 10;
	
	/** for 20 **/
	private static final int TWENTY = 20;
	
	/** for 30 **/
	private static final int THIRTY = 30;
	
	/** for 50 **/
	private static final int FIFTY = 50;
	
	/** for 70 **/
	private static final int SEVENTY = 70;
	
	/** for 937 **/
	private static final int NINEHUNDRED_T_S = 937;
	
	/** for 671 **/
	private static final int SIXHUNDRED_S_O = 671;
	
	/**
	 * This is a constructor for the ControlPanel, 
	 * where it sets the initial preferred size and
	 * initialize and declare sub-panels, layouts,
	 * and other things for the program. 
	 */
	public ControlPanel() {
		super.setLayout(new BorderLayout());
		super.setPreferredSize(new Dimension(SIXHUNDRED_S_O, NINEHUNDRED_T_S));
		l_panel = new EmptyPanel();
		m_panel = new PlayingPanel();
		r_panel = new RightPanel();
		m_panel.setControlPanel(this);
		r_panel.setPlayingPanel(m_panel);
		title = new JLabel("TETRIS!");
		title.setFont(new Font("Cracked", Font.BOLD, SEVENTY));
		title.setForeground(Color.WHITE);
		title.setHorizontalAlignment(SwingConstants.CENTER);
		title.setBorder(BorderFactory.createEmptyBorder(TEN, 0, THIRTY, FIFTY));
		super.add(title, BorderLayout.NORTH);
		super.add(l_panel, BorderLayout.WEST);
		super.add(m_panel, BorderLayout.CENTER);
		super.add(r_panel, BorderLayout.EAST);
		super.setBorder(BorderFactory.createEmptyBorder(TWENTY, 0, 0, 0));
		final JPanel buttonPanel = new JPanel();
		super.add(buttonPanel, BorderLayout.SOUTH);
		super.setBorder(BorderFactory.createEmptyBorder(0, 0, TWENTY, 0));
	}
	
	/**
	 * This method repaints the sub-panels
	 * 
	 * @param g The Graphics object to be drawn on 
	 */
	public void paintComponent(Graphics g) {
		super.paintComponent(g);
		m_panel.repaint();
		r_panel.repaint();
	}
}
